//
//  PNTagView.m
//  LineChart
//
//  Created by apple on 2024/6/13.
//

#import "PNTagView.h"

@interface PNTagView ()
@property (nonatomic, strong) NSString *text;
@property (nonatomic, strong) UIColor *color;
@end

@implementation PNTagView

- (instancetype)initWithFrame:(CGRect)frame text:(NSString *)text color:(nonnull UIColor *)color {
    if (self = [super initWithFrame:frame]) {
        _text = text;
        _color = color;
        self.backgroundColor = [UIColor clearColor];
    }
    return self;
}

- (void)drawRect:(CGRect)rect {
    UIBezierPath *path = [UIBezierPath bezierPath];
    [path moveToPoint:CGPointMake(rect.size.width/2, 0)];
    [path addLineToPoint:CGPointMake(rect.size.width, 15)];
    [path addLineToPoint:CGPointMake(0, 15)];
    [path closePath];
    [self.color setFill];
    [path fill];
    
    [self.text drawInRect:CGRectMake(5, 18, 15, 20) withAttributes:@{
        NSFontAttributeName:[UIFont systemFontOfSize:18],
        NSForegroundColorAttributeName:self.color,
    }];
}

@end
